; (function () {
    //自执行力的 私有方法.
    function getCookieAll() {
        var obj = {};
        var str = document.cookie;
        var arr = str.split("; ");
        for (var i in arr) {
            var resArr = arr[i].split("=");
            obj[resArr[0]] = resArr[1];
        }
        return obj;
    }

    //有个cookie(key,value,{})
    $.cookie = function (name, value, settings = {}) {
        //查看参数的个数
        if (arguments.length == 1) {
            return getCookieAll()[name]; //获取cookie
        } else {
            //设置或修改
            var str = "";
            if (name) {
                str += name + "=" + value + ";";
            }
            // 判断settings 是不是对象
            // if(settings.toString()=="[object Object]"){
            if ($.isPlainObject(settings)) {
                if (typeof (settings.expires) == "number") {
                    var date = new Date();
                    date.setDate(date.getDate() + settings.expires);
                    str += "expires=" + date.toUTCString() + ";";
                }
            }
            document.cookie = str;
        }
    }
})();

